home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / internet / other / mail / pathalia.zoo / src / local.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-12  |  1.8 KB  |  105 lines

  1. /* pathalias -- by steve bellovin, as told to peter honeyman */
  2. #ifndef lint
  3. static char    *sccsid = "@(#)local.c    9.2 88/06/10";
  4. #endif /* lint */
  5.  
  6. #include <stdio.h>
  7. #include "config.h"
  8.  
  9. #ifdef    UNAME
  10. #include <sys/utsname.h>
  11.  
  12. char    *
  13. local()
  14. {
  15.     static struct utsname utsname;
  16.     extern int uname();
  17.  
  18.     (void) uname(&utsname);
  19.     return(utsname.nodename);
  20. }
  21.  
  22. #else /* !UNAME */
  23.  
  24. char    *
  25. local()
  26. {
  27.     static char lname[64];
  28.     extern int gethostname();
  29.  
  30.     (void) gethostname(lname, (int) sizeof(lname));
  31.     lname[sizeof(lname)] = 0;
  32.     return(lname);
  33. }
  34.  
  35. #ifndef GETHOSTNAME
  36.  
  37. #ifndef ATARI
  38.  
  39. STATIC int
  40. gethostname(name, len)
  41.     char *name;
  42.     int len;
  43. {    FILE *whoami;
  44.     char *ptr;
  45.     extern int pclose();
  46.     extern FILE *fopen(), *popen();
  47.  
  48.     *name = '\0';
  49.  
  50.     /* try /etc/whoami */
  51.     if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  52.         (void) fgets(name, len, whoami);
  53.         (void) fclose(whoami);
  54.         if ((ptr = index(name, '\n')) != 0)
  55.             *ptr = '\0';
  56.     }
  57.     if (*name)
  58.         return 0;
  59.  
  60.     /* try /usr/include/whoami.h */
  61.     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  62.         while (!feof(whoami)) {
  63.             char    buf[100];
  64.  
  65.             if (fgets(buf, 100, whoami) == 0)
  66.                 break;
  67.             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  68.                 break;
  69.         }
  70.         (void) fclose(whoami);
  71.         if (*name)
  72.             return 0;
  73.     }
  74.  
  75.     /* ask uucp */
  76.     if ((whoami = popen("uuname -l", "r")) != 0) {
  77.         (void) fgets(name, len, whoami);
  78.         (void) pclose(whoami);
  79.         if ((ptr = index(name, '\n')) != 0)
  80.             *ptr = '\0';
  81.     }
  82.     if (*name)
  83.         return 0;
  84.     
  85.     /* aw hell, i give up!  is this really unix? */
  86.     return -1;
  87. }
  88.  
  89. #else     /* Atari: the system is terminally dumb */
  90.  
  91. STATIC int
  92. gethostname(name, len)
  93.     char *name;
  94.     int len;
  95.   {
  96.     strcpy(name, MYSITE );
  97.     return(0);
  98.   }
  99. #endif    /* ATARI */
  100.  
  101. #endif  /* GETHOSTNAME &*/
  102.  
  103. #endif /* UNAME */
  104.  
  105.